IF @SegmentId IS NULL
BEGIN
    DELETE FROM
        SegmentDocument
    WHERE
        DocumentId = @DocumentId
END
ELSE
BEGIN
    DELETE FROM
        SegmentDocument
    WHERE
        DocumentId = @DocumentId
    AND
        SegmentId = @SegmentId
END
